home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.lev.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  118 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.lev.c version 1.0.1 - somewhat more careful monster regeneration */
  3.  
  4. #include "hack.h"
  5. #ifndef AMIGA
  6. #include <signal.h>    /* Is this really used??? */
  7. #endif
  8. #include <stdio.h>
  9. extern struct monst *restmonchn();
  10. extern struct obj *restobjchn();
  11. extern struct obj *billobjs;
  12. extern char *itoa();
  13.  
  14. extern char nul[];
  15. #ifndef NOWORM
  16. #include   "def.wseg.h"
  17.  
  18. extern struct wseg *wsegs[32], *wheads[32];
  19. extern long wgrowtime[32];
  20. #endif NOWORM
  21.  
  22. getlev(fd)
  23. {
  24.    register struct gen *gtmp;
  25. #ifndef NOWORM
  26.    register struct wseg *wtmp;
  27. #endif NOWORM
  28.    register int tmp;
  29.    long omoves;
  30.  
  31.    if(fd<0 || read(fd, (char *) levl, sizeof(levl)) != sizeof(levl))
  32.       return(1);
  33.    fgold = 0;
  34.    ftrap = 0;
  35.    mread(fd, (char *)&omoves, sizeof(omoves));   /* 0 from MKLEV */
  36.    mread(fd, (char *)&xupstair, sizeof(xupstair));
  37.    mread(fd, (char *)&yupstair, sizeof(yupstair));
  38.    mread(fd, (char *)&xdnstair, sizeof(xdnstair));
  39.    mread(fd, (char *)&ydnstair, sizeof(ydnstair));
  40.  
  41.    fmon = restmonchn(fd);
  42.    if(omoves) {
  43.     /* regenerate animals while on another level */
  44.     long tmoves = (moves > omoves) ? moves-omoves : 0;
  45.     register struct monst *mtmp, *mtmp2;
  46.     extern char genocided[];
  47.     long newhp;
  48.  
  49.        for(mtmp = fmon; mtmp; mtmp = mtmp2) {
  50.       mtmp2 = mtmp->nmon;
  51.       if(index(genocided, mtmp->data->mlet)) {
  52.          mondead(mtmp);
  53.          continue;
  54.         }
  55.         newhp = mtmp->mhp +
  56.             (index("ViT", mtmp->data->mlet) ? tmoves : tmoves/20);
  57.         if(newhp > mtmp->orig_hp)
  58.             mtmp->mhp = mtmp->orig_hp;
  59.         else
  60.             mtmp->mhp = newhp;
  61.        }
  62.    }
  63.  
  64.    setshk();
  65.    setgd();
  66.    gtmp = newgen();
  67.    mread(fd, (char *)gtmp, sizeof(struct gen));
  68.    while(gtmp->gx) {
  69.       gtmp->ngen = fgold;
  70.       fgold = gtmp;
  71.       gtmp = newgen();
  72.       mread(fd, (char *)gtmp, sizeof(struct gen));
  73.    }
  74.    mread(fd, (char *)gtmp, sizeof(struct gen));
  75.    while(gtmp->gx) {
  76.       gtmp->ngen = ftrap;
  77.       ftrap = gtmp;
  78.       gtmp = newgen();
  79.       mread(fd, (char *)gtmp, sizeof(struct gen));
  80.    }
  81.    free((char *) gtmp);
  82.    fobj = restobjchn(fd);
  83.    billobjs = restobjchn(fd);
  84.    rest_engravings(fd);
  85. #ifndef QUEST
  86.    mread(fd, (char *)rooms, sizeof(rooms));
  87.    mread(fd, (char *)doors, sizeof(doors));
  88. #endif QUEST
  89.    if(!omoves) return(0);   /* from MKLEV */
  90. #ifndef NOWORM
  91.    mread(fd, (char *)wsegs, sizeof(wsegs));
  92.    for(tmp = 1; tmp < 32; tmp++) if(wsegs[tmp]){
  93.       wheads[tmp] = wsegs[tmp] = wtmp = newseg();
  94.       while(1) {
  95.          mread(fd, (char *)wtmp, sizeof(struct wseg));
  96.          if(!wtmp->nseg) break;
  97.          wheads[tmp]->nseg = wtmp = newseg();
  98.          wheads[tmp] = wtmp;
  99.       }
  100.    }
  101.    mread(fd, (char *)wgrowtime, sizeof(wgrowtime));
  102. #endif NOWORM
  103.    return(0);
  104. }
  105.  
  106. mread(fd, buf, len)
  107. register int fd;
  108. register char *buf;
  109. register unsigned len;
  110. {
  111. register int rlen;
  112.    rlen = read(fd, buf, (int) len);
  113.    if(rlen != len){
  114.       pline("Read %d instead of %d bytes\n", rlen, len);
  115.       panic("Cannot read %d bytes from file #%d\n", len, fd);
  116.    }
  117. }
  118.